package com.gam.text;

import java.util.Random;
import java.util.Scanner;

public class Game {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        String[] rName=new String[]{"林志玲","薛之谦","舒淇","彭于晏"};
        System.out.println("请选择你的对手(1.林志玲2.薛之谦3.舒淇4.彭于晏)：");

//        给自己和电脑分配角色
        int cr=scan.nextInt();
        Computer computer=new Computer();
        computer.setName(rName[cr]);
        System.out.println("请选择你自己的角色(1.林志玲2.薛之谦3.舒淇4.彭于晏)：");
        int pr=scan.nextInt();
        Person person=new Person();
        person.setName(rName[pr]);
        System.out.println("请选择你要玩的类型（1.一局定胜负2.三局两胜3.五局三胜）");
        int type=scan.nextInt(),n;
        if(type==1){
            n=1;
        }else if(type==2){
            n=3;
        }else {
            n = 5;
        }
        int cResult=0,pResult=0;
        for (int i=1;i<=n;i++) {
            System.out.println("第"+i+"局");
            Random r=new Random();
            int cId=r.nextInt(3);  //产生0~2的整数
            //        人出拳
            System.out.println("请出拳(0.石头1.剪刀2.布)：");
            int pId=scan.nextInt();//        输出电脑人物和自己各自出的是什么拳
            Game game=new Game();
            System.out.println(computer.getName()+"出的是："+game.getById(cId));
            System.out.println(person.getName()+"出的是："+game.getById(pId));
            if (cId == 0 && pId == 1 || cId == 1 && pId == 2 || cId == 2 && pId == 0) {
                cResult++;
                computer.setResult(cResult);
            } else if (cId == pId) {

            } else {
                pResult++;
                person.setResult( pResult);
            }

        }
//        判断输赢
        System.out.println("机："+cResult+"\t\t"+"人："+pResult);
        if(computer.getResult()>person.getResult()){
            System.out.println(computer.getName()+"赢");
        }else if(computer.getResult()==person.getResult()){
            System.out.println("平局");
        }else{
            System.out.println(person.getName()+"赢");
        }
    }


    //   通过Id来得到文字，出的是什么拳
    String getById(int a){
        if(a==0){
            return "石头";
        }else if(a==1){
            return  "剪刀";
        }else{
            return "布";
        }
    }
}
